import { useRequest } from 'ahooks'
import request from '../../utils/request'
export function useTableData ({ tableUrl = '',setTableData,setTotal }) {
    const getTableDataApi = params => {
        return request({
            url: tableUrl,
            data: params
        })
    }
    const { loading, run } = useRequest(getTableDataApi, {
        manual: true,
        onSuccess: res => {
            setTableData(res.data.map((item,index) => {
                return {
                    index: ++index,
                    ...item
                }
            }))
            setTotal(res.total)
        }
    })
    const getTableData = tableParams => {
        run(tableParams)
    }
    return {
        loading,
        getTableData,
    }
}
